package com.ruoyi.course.domain;

import java.util.Date;
import java.util.List;
import java.util.Map;

import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 课件做题记录对象 course_ex_record
 *
 * @author zzx
 * @date 2023-05-05
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@ToString
public class CourseExRecord extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    private Long id;

    /**
     * 用户编号
     */
    @Excel(name = "用户编号")
    private Long userId;

    /**
     * 机构编号
     */
    @Excel(name = "机构编号")
    private Long deptId;

    /**
     * 课件编号
     */
    @Excel(name = "课件编号")
    private Long wareId;

    /**
     * 答案
     */
    @Excel(name = "答案")
    private String answerList;
    private Map<Long,Object> answerMap;

    private List<Long> questionIds;
    private Integer questionTotal;

    /**
     * 对题数
     */
    @Excel(name = "对题数")
    private Long right;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date endTime;

    /**
     * 状态
     */
    @Excel(name = "状态")
    private Integer status;

    /**
     * 预留字段1
     */
    @Excel(name = "预留字段1")
    private String reservedOne;

    /**
     * 预留字段2
     */
    @Excel(name = "预留字段2")
    private String reservedTwo;

    //格式化已完成的题目
    private Map<Long, Boolean> questionAnswers;


    public void setAnswerMap(Map<Long, Object> answerMap) {
        this.answerMap = answerMap;
        this.answerList = JSONUtil.parse(answerMap).toString();
    }

    public void setQuestionIds(List<Long> questionIds) {
        this.questionIds = questionIds;
        if (questionIds!=null){
            this.questionTotal = questionIds.size();
        }
    }
}
